home *** CD-ROM | disk | FTP | other *** search
-
-
-
- TTTTRRRREEEEEEEE((((3333)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((5555 AAAApppprrrriiiillll 1111999999994444)))) TTTTRRRREEEEEEEE((((3333))))
-
-
-
- NNNNAAAAMMMMEEEE
- tree_init, tree_mung, tree_srch, tree_add, tree_delete,
- tree_trav - balanced binary tree routines
-
- SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
- vvvvooooiiiidddd
- ttttrrrreeeeeeee____iiiinnnniiiitttt((((ttttrrrreeeeeeee))))
- vvvvooooiiiidddd ********ttttrrrreeeeeeee;;;;
-
- vvvvooooiiiidddd ****
- ttttrrrreeeeeeee____ssssrrrrcccchhhh((((ttttrrrreeeeeeee,,,, ccccoooommmmppppaaaarrrreeee,,,, ddddaaaattttaaaa))))
- vvvvooooiiiidddd ********ttttrrrreeeeeeee;;;;
- iiiinnnntttt ((((****ccccoooommmmppppaaaarrrreeee))))(((())));;;;
- vvvvooooiiiidddd ****ddddaaaattttaaaa;;;;
-
- vvvvooooiiiidddd
- ttttrrrreeeeeeee____aaaadddddddd((((ttttrrrreeeeeeee,,,, ccccoooommmmppppaaaarrrreeee,,,, ddddaaaattttaaaa,,,, ddddeeeellll____uuuuaaaarrrr))))
- vvvvooooiiiidddd ********ttttrrrreeeeeeee;;;;
- iiiinnnntttt ((((****ccccoooommmmppppaaaarrrreeee))))(((())));;;;
- vvvvooooiiiidddd ****ddddaaaattttaaaa;;;;
- vvvvooooiiiidddd ((((****ddddeeeellll____uuuuaaaarrrr))))(((())));;;;
-
- iiiinnnntttt
- ttttrrrreeeeeeee____ddddeeeelllleeeetttteeee((((ttttrrrreeeeeeee,,,, ccccoooommmmppppaaaarrrreeee,,,, ddddaaaattttaaaa,,,, ddddeeeellll____uuuuaaaarrrr))))
- vvvvooooiiiidddd ********ttttrrrreeeeeeee;;;;
- iiiinnnntttt ((((****ccccoooommmmppppaaaarrrreeee))))(((())));;;;
- vvvvooooiiiidddd ****ddddaaaattttaaaa;;;;
- vvvvooooiiiidddd ((((****ddddeeeellll____uuuuaaaarrrr))))(((())));;;;
-
- iiiinnnntttt
- ttttrrrreeeeeeee____ttttrrrraaaavvvv((((ttttrrrreeeeeeee,,,, ttttrrrraaaavvvv____uuuuaaaarrrr))))
- vvvvooooiiiidddd ********ttttrrrreeeeeeee;;;;
- iiiinnnntttt ((((****ttttrrrraaaavvvv____uuuuaaaarrrr))))(((())));;;;
-
- vvvvooooiiiidddd
- ttttrrrreeeeeeee____mmmmuuuunnnngggg((((ttttrrrreeeeeeee,,,, ddddeeeellll____uuuuaaaarrrr))))
- vvvvooooiiiidddd ********ttttrrrreeeeeeee;;;;
- vvvvooooiiiidddd ((((****ddddeeeellll____uuuuaaaarrrr))))(((())));;;;
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- These functions create and manipulate a balanced binary
- (AVL) tree. Each node of the tree contains the expected
- left & right subtree pointers, a short int balance
- indicator, and a pointer to the user data. On a 32 bit
- system, this means an overhead of 4+4+2+4 bytes per node
- (or, on a RISC or otherwise alignment constrained system
- with implied padding, 4+4+4+4 bytes per node). There is no
- key data type enforced by this package; a caller supplied
- compare routine is used to compare user data blocks.
-
- Balanced binary trees are very fast on searches and
- replacements, but have a moderately high cost for additions
-
-
-
- Page 1 (printed 5/26/99)
-
-
-
-
-
-
- TTTTRRRREEEEEEEE((((3333)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((5555 AAAApppprrrriiiillll 1111999999994444)))) TTTTRRRREEEEEEEE((((3333))))
-
-
-
- and deletions. If your application does a lot more searches
- and replacements than it does additions and deletions, the
- balanced (AVL) binary tree is a good choice for a data
- structure.
-
- _T_r_e_e__i_n_i_t creates an empty tree and binds it to _t_r_e_e (which
- for this and all other routines in this package should be
- declared as a pointer to void or int, and passed by
- reference), which can then be used by other routines in this
- package. Note that more than one _t_r_e_e variable can exist at
- once; thus multiple trees can be manipulated simultaneously.
-
- _T_r_e_e__s_r_c_h searches a tree for a specific node and returns
- either _N_U_L_L if no node was found, or the value of the user
- data pointer if the node was found. _c_o_m_p_a_r_e is the address
- of a function to compare two user data blocks. This routine
- should work much the way _s_t_r_c_m_p(3) does; in fact, _s_t_r_c_m_p
- could be used if the user data was a NUL terminated string.
- _d_a_t_a is the address of a user data block to be used by
- _c_o_m_p_a_r_e as the search criteria. The tree is searched for a
- node where _c_o_m_p_a_r_e returns 0.
-
- _T_r_e_e__a_d_d inserts or replaces a node in the specified tree.
- The tree specified by _t_r_e_e is searched as in _t_r_e_e__s_r_c_h, and
- if a node is found to match _d_a_t_a, then the _d_e_l__u_a_r function,
- if non-NULL, is called with the address of the user data
- block for the node (this routine should deallocate any
- dynamic memory which is referenced exclusively by the node);
- the user data pointer for the node is then replaced by the
- value of _d_a_t_a. If no node is found to match, a new node is
- added (which may or may not cause a transparent rebalance
- operation), with a user data pointer equal to _d_a_t_a. A
- rebalance may or may not occur, depending on where the node
- is added and what the rest of the tree looks like. _T_r_e_e__a_d_d
- will return the _d_a_t_a pointer unless catastrophe occurs in
- which case it will return NULL.
-
- _T_r_e_e__d_e_l_e_t_e deletes a node from _t_r_e_e. A rebalance may or may
- not occur, depending on where the node is removed from and
- what the rest of the tree looks like. _T_r_e_e__d_e_l_e_t_e returns
- TRUE if a node was deleted, FALSE otherwise.
-
- _T_r_e_e__t_r_a_v traverses all of _t_r_e_e, calling _t_r_a_v__u_a_r with the
- address of each user data block. If _t_r_a_v__u_a_r returns FALSE
- at any time, _t_r_e_e__t_r_a_v will immediately return FALSE to its
- caller. Otherwise all nodes will be reached and _t_r_e_e__t_r_a_v
- will return TRUE.
-
- _T_r_e_e__m_u_n_g deletes every node in _t_r_e_e, calling _d_e_l__u_a_r (if it
- is not NULL) with the user data address from each node (see
- _t_r_e_e__a_d_d and _t_r_e_e__d_e_l_e_t_e above). The tree is left in the
- same state that _t_r_e_e__i_n_i_t leaves it in - i.e., empty.
-
-
-
- Page 2 (printed 5/26/99)
-
-
-
-
-
-
- TTTTRRRREEEEEEEE((((3333)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((5555 AAAApppprrrriiiillll 1111999999994444)))) TTTTRRRREEEEEEEE((((3333))))
-
-
-
- BBBBUUUUGGGGSSSS
- Should have a way for the caller to specify application
- specific _m_a_l_l_o_c and _f_r_e_e functions to be used internally
- when allocating meta data.
-
- AAAAUUUUTTTTHHHHOOOORRRR
- Paul Vixie, converted and augumented from Modula-2 examples
- in _A_l_g_o_r_i_t_h_m_s & _D_a_t_a _S_t_r_u_c_t_u_r_e_s, Niklaus Wirth,
- Prentice-Hall, ISBN 0-13-022005-1.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Page 3 (printed 5/26/99)
-
-
-
-